<template>
	<el-card>
		<!-- 搜索 -->
		<el-form :model="searchData" inline ref="searchFormRef" v-resize="searchResize" label-width="110px">
			<el-form-item label="幼儿园名称" prop="kgName">
				<el-input v-model="searchData.kgName" placeholder="请输入幼儿园名称" clearable></el-input>
			</el-form-item>
			
			<el-form-item label="幼儿园联系电话" prop="kgPhone">
				<el-input v-model="searchData.kgPhone" placeholder="请输入电话" clearable></el-input>
			</el-form-item>
			
			<el-form-item>
				<el-button icon="el-icon-search" type="primary" @click="searchClick">搜索</el-button>
				<el-button icon="el-icon-refresh" @click="resetClick">重置</el-button>
				<el-button icon="el-icon-plus" type="success" v-has="'sys:kg:add'" @click="addShowClick">新增</el-button>
			</el-form-item>
		</el-form>
		<!-- 表格渲染 -->
		<YwTable ref="tableRef" :searchData="searchData" :tableProps="tableProps" api="sysKgFindAllByPage">
			<el-table-column slot="table_oper" label="操作" fixed="right" width="170px">
				<template v-slot="scope">
						<el-button type="text" icon="el-icon-edit" @click="editShowClick(scope.row)"
							v-has="'sys:kg:edit'">修改</el-button>
						<el-button type="text" icon="el-icon-delete" @click="deleteClick(scope.row)"
							v-has="'sys:kg:delByIds'">删除</el-button>
				</template>
			</el-table-column>
		</YwTable>

		<!-- 添加/修改 -->
		<YwDialog @confirm="confirmClick" width="650px" ref="ywDialogRef" title="修改信息">
			<template slot="form">
				<el-form :model="curData" inline ref="curFormRef" label-width="95px" :show-message="false">
				
					<el-form-item label="幼儿园名称" prop="kgName" required>
						<el-input v-model="curData.kgName" placeholder="请输入幼儿园名称"></el-input>
					</el-form-item>
			
					<el-form-item label="幼儿园地址" prop="kgAddress" required>
						<el-input v-model="curData.kgAddress" placeholder="请输入幼儿园地址"></el-input>
					</el-form-item>

					<el-form-item label="幼儿园电话" prop="kgPhone" required>
						<el-input v-model="curData.kgPhone" placeholder="请输入幼儿园电话"></el-input>
					</el-form-item>

					<!-- <el-form-item label="幼儿园小程序编码" prop="kg" >
						<el-input v-model="curData.kgCode" placeholder="请输入幼儿园编码"></el-input>
					</el-form-item> -->
			
				</el-form>
			</template>
		</YwDialog>

	</el-card>
</template>

<script>
	export default {

		data() {
			return {
				//搜索条件
				searchData: {
					kgName: null,
					kgPhone: null,
					
				},
				//添加信息数据
				//修改信息数据
				//表单的值
				curData: {
					kgName: null,
					kgAddress: null,
					kgPhone: null,
					//kgCode: null

				},
				//表格数据
				tableProps: [{
						label: "幼儿园名称",
						prop: "kgName"
					},
					{
						label: "幼儿园地址",
						prop: "kgAddress"
					},
				
					{
						label: "幼儿园电话",
						prop: "kgPhone"
					},
					{
						label: "幼儿园小程序编码",
						prop: "kgCode"
					},

				],
				
			};
		},
		mounted() {
			this.$nextTick(() => {
				this.$refs.tableRef.shuaxin(this.searchData)
			})

		},
		methods: {
			//搜索重置
			searchResize(data) {
				this.$refs.tableRef.refreshSize(data)
			},

			
			//添加/修改表单的确认按钮
			confirmClick() {
				let data = JSON.parse(JSON.stringify(this.curData))
				console.log(data)
				this.$refs.curFormRef.validate(async (valid) => {
					if (valid) {
						if (data.id) {
							//含有id , 修改操作
							await this.$api.sysKgEdit(data)
						} else {
							//修改操作
							await this.$api.sysKgAdd(data);
						}
						this.$refs.ywDialogRef.close()
						this.searchClick()
					}
				});
			},
			//删除事件
			deleteClick(row) {
				this.$common.msgBoxDel(() => {
					this.$api.sysKgDelByIds(row.id).then(res => {
						this.searchClick();
					});
				})
			},
			//新增按钮
			addShowClick() {
				this.curData = {
					kgName: null,
					kgAddress: null,
					kgPhone: null,
				
				}
				this.$refs.ywDialogRef.open()
			},
			//修改按钮
			editShowClick(row) {
				//给表单赋值

				this.$api.sysKgFindById(row.id).then((result) => {
					this.curData = result;//实现表单赋值
				})	
				this.$refs.ywDialogRef.open()
			},

			//搜索按钮
			searchClick() {
				this.$refs.tableRef.shuaxin(this.searchData)
			},
			//重置按钮
			resetClick() {
				this.$refs.searchFormRef.resetFields();
				this.searchClick()
			},
		},
	};
</script>

<style lang="scss" scoped>
</style>
